var util = require('../../core/module.js');

var config = new util.ConfigModule('security'); // configuration file


exports.getSecurityConf = function (req, res)
{
	var id = req.params.id;
	config.get(id, function(err, conf) // get the module config
	{
		res.end(JSON.stringify(conf));
	});
}

exports.putSecurityConf = function (req, res) {

	var id = req.params.id; // module id
	var secured = req.body.secured;
	var resJson = {};
		
	if (id == {} || secured == undefined)
	{
		resJson.error = "Paramètres manquants";
		res.end(JSON.stringify(resJson));
		
	} else {
	
		var securedBool = (secured === 'true'); // String to bool conversion
		
		console.log('Security is set to "'+secured+'"" for module with id "'+id+'"');
		config.set(id, {'secured': securedBool}, function(error) {
			res.json({ 'code':"OK", 'secured':securedBool });
		}); // set the config for the module
	}
};
